// components/reason/reason.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    title: {
      type: String,
      value: ''
    },
    name: {
      type: String,
      value: '',
      observer: function (newVal) {
        if (newVal) {
          this.setData({
            reasonName: newVal
          })
        }
      }
    },
    type: {
      type: Number,
      value: '',
      observer: function (newVal) {
        console.log(newVal)
        let reason = []
        if (newVal === 20) {
          reason = [{
              id: '1',
              name: '质量问题/商品损坏/包装脏污'
            },
            {
              id: '2',
              name: '我不想要了'
            },
            {
              id: '3',
              name: '收到的商品与描述不符'
            },
            {
              id: '4',
              name: '发错/少发商品'
            },
            {
              id: '4',
              name: '其他'
            }
          ]
        }else if(newVal === 10){
          reason = [{
            id: '1',
            name: '地址写错了'
          },
          {
            id: '2',
            name: '配送时间不符/我不想要了'
          },
          {
            id: '3',
            name: '商品降价'
          },
          {
            id: '4',
            name: '未收到货'
          },
          {
            id: '4',
            name: '货物破损/拒签'
          }
        ]}
        this.setData({
          reasonData: reason
        })
      }
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    reasonName: '',
    reasonData: []
  },

  /**
   * 组件的方法列表
   */
  methods: {
    selectReason(e) {
      let name = e.currentTarget.dataset.name;
      this.setData({
        reasonName: name
      })
      this.triggerEvent('detail', name);
    },
    close() {
      this.triggerEvent('close')
    },
  }
})